<?php
// .-----------------------------------------------------------------------------------
// | WE TRY THE BEST WAY 杭州博也网络科技有限公司
// |-----------------------------------------------------------------------------------
// | Author: 贝贝 <hebiduhebi@163.com>
// | Copyright (c) 2013-2016, http://www.itboye.com. All Rights Reserved.
// |-----------------------------------------------------------------------------------
namespace Shop\Api;

use Common\Api\Api;

use Shop\Model\ProductGroupModel;

class ProductGroupApi extends  Api{

    /**
     * 查询，不分页
     */
    const QUERY_NO_PAGING = "Shop/ProductGroup/queryNoPaging";
    /**
     * 添加
     */
    const ADD = "Shop/ProductGroup/add";
    /**
     * 保存
     */
    const SAVE = "Shop/ProductGroup/save";
    /**
     * 保存根据ID主键
     */
    const SAVE_BY_ID = "Shop/ProductGroup/saveByID";

    /**
     * 删除
     */
    const DELETE = "Shop/ProductGroup/delete";

    /**
     * 查询
     */
    const QUERY = "Shop/ProductGroup/query";
    /**
     * 查询一条数据
     */
    const GET_INFO = "Shop/ProductGroup/getInfo";

    const QUERY_WITH_PRODUCT="Shop/ProductGroup/queryWithProduct";

	protected function _init(){
		$this->model = new ProductGroupModel();
	}

    public function queryWithProduct($map){

        $map['status'] = 1;
        $result = $this->model->alias('g')->join("LEFT JOIN __PRODUCT__ p on p.id = g.p_id")->field(" p.id,name,p.price as product_price,synopsis,ori_price,main_img,quantity,source,dt_origin_country,dt_goods_unit,g.g_id,g.p_id,g.start_time,g.end_time,g.price")->where($map)->order('end_time desc')->select();

        if ($result === false) {
            $error = $this -> model -> getDbError();
            return $this -> apiReturnErr($error);
        }
        return $this -> apiReturnSuc($result);
    }
	
}

